<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Weixin\Controller;
use OT\DataDictionary;


/**
 * 前台首页控制器
 * 主要获取首页聚合数据
 */
class IndexController extends WeixinController {
    protected function _initialize(){
        //require_once('ThinkPHP/Library/Vendor/api_payment/llpaypayment.php');
        require_once('ThinkPHP/Library/Vendor/OCR_API.php');


        /* 读取站点配置 */
        $config = api('Config/lists');
        C($config); //添加配置
        if(!C('WEB_SITE_CLOSE')){
            $this->error('站点已经关闭，请稍后访问~');
        }
        $options = array(
            'token'     => $this->token,   // 填写你设定的key
            'appid'     => $this->appid,    // 填写高级调用功能的appid
            'appsecret' => $this->appsecret // 填写高级调用功能的密钥
        );
        $this->weixin = new \Common\Extend\Wechat\Wechat($options);
        $weixin = cookie('WeixinLogin');
        if(empty($weixin)){
            $this->oauth();
        }else{
            $this->uid          = $weixin['uid'];
            $this->access_token = $weixin['access_token'];
            $this->openid       = $weixin['openid'];
        }
        $where['id'] =$this->uid;
        $count = D('ucenter_member')->where($where)->getField('mobile');
        if(empty($count)){
            $this->redirect('User/mobile');
        }
        
    }
    

    public function index(){
        
        $model = M('Member');
        $info  = $model->where("uid={$this->uid}")->find();
        $re    =D('Realname')->where("uid={$this->uid}")->find();      
        $this->assign('info',$info);
        $this->assign('realname',$re);
        C('WEB_SITE_TITLE','我的账户');
        $this->display();
    }


	//系统首页
    public function index2(){

        $app = cookie('WeixinLogin');
        print_r($app);exit;
        $api = new \Common\Extend\Api\ApiClient();
        $api = $api->credit();
       /* $api->method    = 'api.education.get';
        $api->username  = '18776030402';
        $api->password  = base64_encode('0516Chun!');*/
        /*$api->method    = 'api.common.getResult';
        $api->token = '1278efea10fb4dbcbd64c5ab9fcc3fb3'; //1278efea10fb4dbcbd64c5ab9fcc3fb3
        $api->bizType='education';*/
        /*手机*/

        $api->method     = 'api.mobile.get';
        $api->username    = '13036884445';
        $api->password    = base64_encode('611656'); //267052ea8be44c4badeb1c43273e51ff

        /*
        $api->method     = 'api.mobile.area';
        $api->mobileNo   = '13036884445';*/

       /* $api->method    = 'api.common.getReport';
        $api->token = '1278efea10fb4dbcbd64c5ab9fcc3fb3'; //1278efea10fb4dbcbd64c5ab9fcc3fb3
        $api->bizType='mobile';
        $api->ApiUrl = 'https://t.limuzhengxin.cn/api/gateway';*/
        $data=$api->Send('post','json')->data();


        print_r($data);exit;
        exit;
        C('WEB_SITE_TITLE','基本信息');
        $this->display();
    }


    public function test(){
        $client = new \Predis\Client();
        $client->set('foo', 'bar99');
        $value = $client->get('foo');
        echo $value;
    }

}